<template>
  <div class="system-role-container layout-padding">
    <div class="system-role-padding layout-padding-auto layout-padding-view">
      <div class="m-header">
        <div class="pro-name">
          <el-input
            clearable
            size="small"
            placeholder="请输入项目名称或项目编号"
            v-model="proName"
            :suffix-icon="Search"
          />
          <el-button
            size="small"
            @click="newPro"
            :icon="CirclePlus"
            type="primary"
            >新建</el-button
          >
        </div>
      </div>

      <div class="table_content">
        <el-table
          ref="table_s_exp"
          :height="activeHeight"
          style="width: 100%"
          :header-cell-style="{ background: '#fafbfc', color: '#333333' }"
          :data="tableDataPro"
          :expand-row-keys="expandArr"
          @expand-change="expandChange"
          :row-key="
            (row) => {
              return row.proj_oid;
            }
          "
        >
          <el-table-column type="expand">
            <template #default="props">
              <div class="bvacs">
                <div class="table_box">
                  <div class="backgroun_border">
                    <el-tabs
                      v-model="tableTitleName"
                      @tab-change="(name) => change_pages(name, props)"
                      tab-position="left"
                      class="demo-tabs"
                    >
                      <el-tab-pane name="主项管理" label="主项管理">
                        <div
                          v-if="tableTitleName == '主项管理'"
                          class="table_content_changes"
                        >
                          <div class="button_poastion_flex_iem">
                            <el-button
                              size="small"
                              type="primary"
                              class="dr2333"
                              :icon="CirclePlus"
                              @click="addNEWpro"
                              >新建</el-button
                            >
                            &nbsp;&nbsp;&nbsp;
                            <el-button
                              v-if="false"
                              size="small"
                              type="success"
                              class="dr2333"
                              :icon="CirclePlus"
                            ></el-button>
                            &nbsp;&nbsp;
                            <el-popconfirm
                              v-if="false"
                              @confirm="delAll"
                              title="确定要删除吗？"
                            >
                              <template #reference>
                                <el-button
                                  v-if="false"
                                  size="small"
                                  class="delArr"
                                  :icon="Delete"
                                  >批量删除</el-button
                                >
                              </template>
                            </el-popconfirm>

                            <el-upload
                              action="#"
                              accept="xlsx"
                              :http-request="uploadExcel"
                              :show-file-list="false"
                              style="display: inline-block"
                              class="buttonposition"
                            >
                              <el-button
                                type="success"
                                size="small"
                                :icon="Upload"
                                class="dr23"
                                >批量导入主项</el-button
                              >
                            </el-upload>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <el-button
                              size="small"
                              class="dr"
                              type="warning"
                              :icon="Download"
                              @click="downloadTemplate"
                              >下载模板</el-button
                            >
                          </div>
                          <el-table
                            size="small"
                            :data="dataSData"
                            class="roledata"
                            @selection-change="handleSelectionChange"
                            height="350"
                          >
                            <el-table-column type="selection" />
                            <el-table-column
                              type="index"
                              width="120"
                              label="序号"
                            />
                            <el-table-column
                              sortable
                              prop="unit_no"
                              label="主项号"
                            >
                              <!-- <template #header>
                              <div class="filter_item">
                                <span>主项号</span>
                                <filterCom :options="allproSubcode" @chooseItem="chooseproSubcode"></filterCom>
                              </div>
                            </template> -->
                            </el-table-column>
                            <el-table-column prop="unit_name" label="主项名称">
                              <!-- <template #header>
                              <div class="filter_item">
                                <span>主项名称</span>
                                <filterCom :options="allproSubName" @chooseItem="chooseproSubName"></filterCom>
                              </div>
                            </template> -->
                            </el-table-column>
                            <el-table-column
                              prop="note"
                              label="备注"
                            ></el-table-column>
                            <el-table-column width="150" label="操作">
                              <template #default="scope">
                                <span
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                    font-size: 12px;
                                  "
                                  size="small"
                                  @click="handleEdit2(scope.$index, scope.row)"
                                >
                                  编辑
                                </span>
                                <el-popconfirm
                                  title="确定要删除吗?"
                                  @confirm="
                                    confirmEvent2(scope.$index, scope.row)
                                  "
                                >
                                  <template #reference>
                                    <span
                                      style="
                                        color: #f56c6c;
                                        cursor: pointer;
                                        font-size: 12px;
                                      "
                                      >删除</span
                                    >
                                  </template>
                                </el-popconfirm>
                              </template>
                            </el-table-column>
                          </el-table>
                          <div v-if="false" class="page_pagiation">
                            <el-pagination
                              v-model:current-page="pageNum2"
                              v-model:page-size="pageSize2"
                              :page-sizes="[10, 30, 50]"
                              background
                              layout="total, sizes, prev, pager, next"
                              :total="total2"
                              @size-change="handleSizeChange2"
                              @current-change="handleCurrentChange2"
                            />
                          </div>
                        </div>
                      </el-tab-pane>
                      <el-tab-pane name="用户管理" label="用户管理">
                        <div
                          v-if="tableTitleName == '用户管理'"
                          class="table_content_changes"
                        >
                          <div class="button_poastion_flex_iem">
                            <el-button
                              size="small"
                              type="primary"
                              class="dr2333"
                              :icon="CirclePlus"
                              @click="addNEWproUser"
                              >新建</el-button
                            >
                          </div>
                          <el-table
                            size="small"
                            :data="userTable"
                            class="roledata"
                            height="350"
                          >
                            <el-table-column prop="user_role" label="角色名称">
                              <!-- <template #header>
                              <div class="filter_item">
                                <span>主项号</span>
                                <filterCom :options="allproSubcode" @chooseItem="chooseproSubcode"></filterCom>
                              </div>
                            </template> -->
                            </el-table-column>
                            <el-table-column prop="user_account" label="用户名">
                              <template #default="scope">
                                <el-tag
                                  style="margin-right: 5px; margin-bottom: 5px"
                                  size="small"
                                  v-for="(item, index) in scope.row.person"
                                  :key="index"
                                  type="danger"
                                >
                                  {{ item.user_account }}
                                </el-tag>
                              </template>
                            </el-table-column>
                            <el-table-column prop="user_name" label="人员名称">
                              <template #default="scope">
                                <el-tag
                                  style="margin-right: 5px; margin-bottom: 5px"
                                  size="small"
                                  v-for="(item, index) in scope.row.person"
                                  :key="index"
                                  type="success"
                                >
                                  {{ item.user_name }}
                                </el-tag>
                              </template>
                            </el-table-column>

                            <el-table-column width="150" label="操作">
                              <template #default="scope">
                                <span
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                    font-size: 12px;
                                  "
                                  size="small"
                                  @click="
                                    handleEdit2User(scope.$index, scope.row)
                                  "
                                >
                                  编辑
                                </span>
                                <el-popconfirm
                                  title="确定要删除吗?"
                                  @confirm="
                                    confirmEvent2User(scope.$index, scope.row)
                                  "
                                >
                                  <template #reference>
                                    <span
                                      style="
                                        color: #f56c6c;
                                        cursor: pointer;
                                        font-size: 12px;
                                      "
                                      >删除</span
                                    >
                                  </template>
                                </el-popconfirm>
                              </template>
                            </el-table-column>
                          </el-table>
                          <div v-if="false" class="page_pagiation">
                            <el-pagination
                              v-model:current-page="pageNum2"
                              v-model:page-size="pageSize2"
                              :page-sizes="[10, 30, 50]"
                              background
                              layout="total, sizes, prev, pager, next"
                              :total="total2"
                              @size-change="handleSizeChange2"
                              @current-change="handleCurrentChange2"
                            />
                          </div>
                        </div>
                      </el-tab-pane>
                      <el-tab-pane name="统一规定" label="统一规定">
                        <div
                          v-if="tableTitleName == '统一规定'"
                          class="table_content_changes"
                        >
                          <div
                            style="display: flex; flex-direction: row-reverse"
                            class="button_poastion"
                          >
                            <el-upload
                              action="#"
                              :http-request="uploadRequest"
                              :show-file-list="false"
                              style="display: inline-block"
                              class="buttonposition"
                            >
                              <el-button
                                size="small"
                                :icon="Upload"
                                class="dr23"
                                >导入</el-button
                              >
                            </el-upload>
                            &nbsp;&nbsp;&nbsp;
                            <el-popconfirm
                              @confirm="delAllRules"
                              title="确定要删除吗？"
                            >
                              <template #reference>
                                <el-button
                                  size="small"
                                  class="delArr"
                                  :icon="Delete"
                                  >批量删除</el-button
                                >
                              </template>
                            </el-popconfirm>
                          </div>
                          <el-table
                            size="small"
                            :data="tableRuleData"
                            class="roledata"
                            @selection-change="handleSelectionChangeRule"
                            height="350"
                          >
                            <el-table-column type="selection" />
                            <el-table-column
                              type="index"
                              width="80"
                              label="序号"
                              align="center"
                            />
                            <el-table-column
                              prop="file_name"
                              label="文档名称"
                              sortable
                            >
                            </el-table-column>
                            <el-table-column
                              width="200"
                              prop="file_size_inBytes"
                              label="文件大小"
                              sortable
                            >
                              <template #default="scope">
                                {{ convertFileSize(scope.row.file_size_inBytes) }} KB
                              </template>
                            </el-table-column>
                            <el-table-column
                              label="发布日期"
                              prop="create_time"
                              width="200px"
                              sortable
                            >
                            </el-table-column>
                            <el-table-column width="250" label="操作">
                              <template #default="scope">
                                <span
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                  "
                                  size="small"
                                  @click="previewRule(scope.row)"
                                  >下载</span
                                >

                                <el-popconfirm
                                  title="确定要删除吗?"
                                  @confirm="
                                    confirmDeleteRule(scope.$index, scope.row)
                                  "
                                >
                                  <template #reference>
                                    <span
                                      style="color: #189eff; cursor: pointer"
                                      >删除</span
                                    >
                                  </template>
                                </el-popconfirm>
                              </template>
                            </el-table-column>
                          </el-table>
                          <div style="display: none" class="page_pagiation">
                            <el-pagination
                            v-if="false"
                              v-model:current-page="pageNumRule"
                              v-model:page-size="pageSizeRule"
                              :page-sizes="[10, 30, 50]"
                              background
                              layout="total, sizes, prev, pager, next"
                              :total="totalRule"
                              @size-change="handleSizeChangeRule"
                              @current-change="handleCurrentChangeRule"
                            />
                          </div>
                        </div>
                      </el-tab-pane>
                      <el-tab-pane name="设备联系单" label="设备联系单">
                        <div
                          v-if="tableTitleName == '设备联系单'"
                          class="table_content_changes"
                        >
                          <div
                            style="display: flex; flex-direction: row-reverse"
                            class="button_poastion"
                          >
                            <el-upload
                              action="#"
                              :http-request="uploadRequest2"
                              :show-file-list="false"
                              style="display: inline-block"
                              class="buttonposition"
                            >
                              <el-button
                                size="small"
                                :icon="Upload"
                                class="dr23"
                                >导入</el-button
                              >
                            </el-upload>
                            &nbsp;&nbsp;&nbsp;
                            <el-popconfirm
                              @confirm="delAllRules"
                              title="确定要删除吗？"
                            >
                              <template #reference>
                                <el-button
                                  size="small"
                                  class="delArr"
                                  :icon="Delete"
                                  >批量删除</el-button
                                >
                              </template>
                            </el-popconfirm>
                          </div>
                          <el-table
                            size="small"
                            :data="tableRuleData2"
                            class="roledata"
                            @selection-change="handleSelectionChangeRule"
                            height="350"
                          >
                            <el-table-column type="selection" />
                            <el-table-column
                              type="index"
                              width="80"
                              label="序号"
                              align="center"
                            />
                            <el-table-column
                              prop="file_name"
                              label="文档名称"
                              sortable
                            >
                            </el-table-column>
                            <el-table-column
                              width="200"
                              prop="file_size_inBytes"
                              label="文件大小"
                              sortable
                            >
                              <template #default="scope">
                                {{  convertFileSize(scope.row.file_size_inBytes)}} 
                              </template>
                            </el-table-column>
                            <el-table-column
                              label="发布日期"
                              prop="create_time"
                              width="200px"
                              sortable
                            >
                            </el-table-column>
                            <el-table-column width="250" label="操作">
                              <template #default="scope">
                                <span
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                  "
                                  size="small"
                                  @click="previewRule(scope.row)"
                                  >下载</span
                                >

                                <el-popconfirm
                                  title="确定要删除吗?"
                                  @confirm="
                                    confirmDeleteRule(scope.$index, scope.row)
                                  "
                                >
                                  <template #reference>
                                    <span
                                      style="color: #189eff; cursor: pointer"
                                      >删除</span
                                    >
                                  </template>
                                </el-popconfirm>
                              </template>
                            </el-table-column>
                          </el-table>
                          <div style="display: none" class="page_pagiation">
                            <el-pagination
                            v-if="false"
                              v-model:current-page="pageNumRule"
                              v-model:page-size="pageSizeRule"
                              :page-sizes="[10, 30, 50]"
                              background
                              layout="total, sizes, prev, pager, next"
                              :total="totalRule"
                              @size-change="handleSizeChangeRule"
                              @current-change="handleCurrentChangeRule"
                            />
                          </div>
                        </div>
                      </el-tab-pane>
                      <el-tab-pane name="通知公告" label="通知公告">
                        <div
                          v-if="tableTitleName == '通知公告'"
                          class="table_content_changes"
                        >
                          <div class="button_poastion_flex_iem">
                            <el-button
                              size="small"
                              type="primary"
                              class="dr2333"
                              :icon="CirclePlus"
                              @click="addNEWproNotice"
                              >新建</el-button
                            >
                            &nbsp;&nbsp;&nbsp;
                            <!-- <el-popconfirm
                              @confirm="delAll"
                              title="确定要删除吗？"
                            >
                              <template #reference>
                                <el-button
                                  size="small"
                                  class="delArr"
                                  :icon="Delete"
                                  >批量删除</el-button
                                >
                              </template>
                            </el-popconfirm> -->
                          </div>
                          <el-table
                            size="small"
                            :data="getNoticeDataTabel"
                            class="roledata"
                            height="350"
                          >
                            <el-table-column
                              type="index"
                              width="120"
                              label="序号"
                            />
                            <el-table-column
                              show-overflow-tooltip
                              width="250"
                              prop="content"
                              label="公告内容"
                            >
                            </el-table-column>
                            <el-table-column prop="state" label="公告状态">
                              <template #default="scope">
                                <el-tag
                                  type="success"
                                  size="small"
                                  v-if="scope.row.state == '已发布'"
                                  >{{ scope.row.state }}</el-tag
                                >
                                <el-tag
                                  type="warning"
                                  size="small"
                                  v-if="scope.row.state == '未发布'"
                                  >{{ scope.row.state }}</el-tag
                                >
                                <el-tag
                                  type="danger"
                                  size="small"
                                  v-if="scope.row.state == '已删除'"
                                  >{{ scope.row.state }}</el-tag
                                >
                              </template>
                            </el-table-column>
                            <el-table-column
                              prop="publish_time"
                              label="发布日期"
                            >
                            </el-table-column>
                            <el-table-column width="150" label="操作">
                              <template #default="scope">
                                <span
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                    font-size: 12px;
                                  "
                                  size="small"
                                  @click="addNEWproNotice(scope.row)"
                                >
                                  编辑
                                </span>
                                <span
                                  v-if="scope.row.state !== '已发布'"
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                    font-size: 12px;
                                  "
                                  size="small"
                                  @click="addNEWproNoticeF('已发布', scope.row)"
                                >
                                  发布
                                </span>
                                <span
                                  v-if="scope.row.state == '已发布'"
                                  style="
                                    color: #1890ff;
                                    margin-right: 1em;
                                    cursor: pointer;
                                    font-size: 12px;
                                  "
                                  size="small"
                                  @click="addNEWproNoticeF('未发布', scope.row)"
                                >
                                  取消发布
                                </span>
                                <el-popconfirm
                                  title="确定要删除吗?"
                                  @confirm="
                                    addNEWproNoticeF('已删除', scope.row)
                                  "
                                >
                                  <template #reference>
                                    <span
                                      style="
                                        color: #f56c6c;
                                        cursor: pointer;
                                        font-size: 12px;
                                      "
                                      >删除</span
                                    >
                                  </template>
                                </el-popconfirm>
                              </template>
                            </el-table-column>
                          </el-table>
                          <div v-if="false" class="page_pagiation">
                            <el-pagination
                              v-if="false"
                              v-model:current-page="pageNum2"
                              v-model:page-size="pageSize2"
                              :page-sizes="[10, 30, 50]"
                              background
                              layout="total, sizes, prev, pager, next"
                              :total="total2"
                              @size-change="handleSizeChange2"
                              @current-change="handleCurrentChange2"
                            />
                          </div>
                        </div>
                      </el-tab-pane>
                      <el-tab-pane name="校验规则" label="校验规则">
                        <div
                          v-if="tableTitleName == '校验规则'"
                          class="table_content_changes"
                        >
                          校验规则
                        </div>
                      </el-tab-pane>

                      <el-tab-pane name="设计基础数据" label="设计基础数据">
                        <div
                          v-if="tableTitleName == '设计基础数据'"
                          class="table_content_changes"
                          style="
                            width: 95%;
                            padding-left: 20px;
                            padding-top: 20px;
                          "
                        >
                          <div
                            style="
                              font-weight: bolder;
                              font-size: 16px;
                              margin-bottom: 20px;
                            "
                          >
                            设计基础数据
                          </div>
                          <el-form
                            ref="dataFormRefNew"
                            :model="dataForm"
                            size="small"
                           
                            class="demo-ruleForm-new"
                          >

                          <div  style='display:flex;width:100%'>
                          <div style='width:33.3%'>

                          
                            <el-form-item
                              label="地震设防烈度："
                              prop="proj_name"
                              label-width="100px"
                            
                            >

                             <el-select
                        placeholder="请选择设防烈度"
                        v-model="
                          dataForm.seismic_design_intensity
                        "
                        style="width:55%"
                      >
                        <el-option
                          v-for="item in [
                            {
                              value: '6',
                              label: '6度',
                            },
                            {
                              value: '7',
                              label: '7度',
                            },
                            {
                              value: '8',
                              label: '8度',
                            },
                            {
                              value: '9',
                              label: '9度',
                            },
                          ]"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                              
                            </el-form-item>
                            <el-form-item  label-width="100px" label="地震加速度：" prop="proj_name">
                              <el-select
                        placeholder="请选择加速度"
                        v-model="
                          dataForm.seismic_acceleration
                        "
                        style="width: 55%"
                      >
                        <el-option
                          v-for="item in [
                            {
                              value: '0.05g',
                              label: '0.05g',
                            },
                            {
                              value: '0.1g',
                              label: '0.1g',
                            },
                            {
                              value: '0.15g',
                              label: '0.15g',
                            },
                            {
                              value: '0.2g',
                              label: '0.2g',
                            },
                            {
                              value: '0.3g',
                              label: '0.3g',
                            },
                            {
                              value: '0.4g',
                              label: '0.4g',
                            },
                          ]"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                             
                            </el-form-item>
                            <el-form-item
                             label-width="100px"
                              label="设计地震分组："
                              prop="proj_name"
                            >

                             <el-select
                        placeholder="请选择分组"
                        v-model="
                          dataForm.seismic_design_category
                        "
                        style="width: 55%"
                      >
                        <el-option
                          v-for="item in [
                            {
                              value: '第一组',
                              label: '第一组',
                            },
                            {
                              value: '第二组',
                              label: '第二组',
                            },
                            {
                              value: '第三组',
                              label: '第三组',
                            },
                          ]"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                              
                            </el-form-item>

                            

                            <el-form-item
                             label-width="100px"
                              label="地面粗糙度："
                              prop="proj_name"
                            >
                            <el-select
                        placeholder="请选择粗糙度"
                        v-model="dataForm.terrain_roughness"
                        style="width: 55%"
                      >
                        <el-option
                          v-for="item in [
                            {
                              value: 'A类',
                              label: 'A类',
                            },
                            {
                              value: 'B类',
                              label: 'B类',
                            },
                            {
                              value: 'C类',
                              label: 'C类',
                            },
                            {
                              value: 'D类',
                              label: 'D类',
                            },
                          ]"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                             
                            </el-form-item>

                           


                            <el-form-item

                             label-width="100px"
                              label="场地土类别："
                              prop="proj_name"
                            >
                            <el-select
                        placeholder="请选择类别"
                        v-model="dataForm.site_class"
                        style="width: 55%"
                      >
                        <el-option
                          v-for="item in [
                            {
                              value: 'Ⅰ类',
                              label: 'Ⅰ类',
                            },
                            {
                              value: 'Ⅱ类',
                              label: 'Ⅱ类',
                            },
                            {
                              value: 'Ⅲ类',
                              label: 'Ⅲ类',
                            },
                            {
                              value: 'Ⅳ类',
                              label: 'Ⅳ类',
                            },
                          ]"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                             
                            </el-form-item>
                          </div>

                          <div style='width:33.3%'>

                               <el-form-item
                                label-width="235px"
                              label="月平均最低气温最低值（非大型储罐）："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.month_lowest_temp"
                                placeholder="请输入"
                              />
                            </el-form-item>
                            <el-form-item
                              label-width="235px"
                              label="日平均最低气温最低值（大型储罐）："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.day_lowest_temp"
                                placeholder="请输入"
                              />
                            </el-form-item>
                            <el-form-item    label-width="235px" label="风压（pa）：" prop="proj_no">
                              <el-input
                                v-model="dataForm.wind_pressure"
                                placeholder="请输入风压（pa）"
                              />
                            </el-form-item>
                            <el-form-item   label-width="235px" label="雪压（pa）：" prop="proj_name">
                              <el-input
                                v-model="dataForm.snow_pressure"
                                placeholder="请输入雪压（pa）"
                              />
                            </el-form-item>

                          </div>



                            <div style='width:33.3%'>

                               <el-form-item
                                label-width="219px"
                              label="反应器、塔器设计使用年限："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.design_service_life_reactor_tower"
                                placeholder="请输入"
                              />
                            </el-form-item>
                             <el-form-item
                                label-width="219px"
                              label="容器、换热器设计使用年限："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.design_service_life_vessel_bem"
                                placeholder="请输入"
                              />
                            </el-form-item>
                             <el-form-item
                                label-width="219px"
                              label="球罐设计使用年限："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.design_service_life_sphericaltank"
                                placeholder="请输入"
                              />
                            </el-form-item>
                             <el-form-item
                                label-width="219px"
                              label="大型储罐设计使用年限："
                              prop="proj_name"
                            >
                              <el-input
                                v-model="dataForm.design_service_life_storagetank"
                                placeholder="请输入"
                              />
                            </el-form-item>

                          </div>
                        </div>


                           
                            <el-form-item
                            style='margin-top:10px'
                            >

                  
                              <div class="button_footer">
                                &nbsp;&nbsp;&nbsp;
                                <el-button
                                  type="primary"
                                  @click="submitDataFormNew(dataFormRefNew)"
                                  >保存</el-button
                                >
                              </div>
                            </el-form-item>
                          </el-form>
                        </div>
                      </el-tab-pane>
                    </el-tabs>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            type="index"
            width="80"
            label="序号"
            align="center"
          />
          <el-table-column
            width="120"
            show-overflow-tooltip
            label="项目代号"
            prop="proj_no"
          ></el-table-column>
          <el-table-column
            min-width="300"
            show-overflow-tooltip
            label="项目名称"
            prop="proj_name"
          ></el-table-column>
          <el-table-column
            width="120"
            label="专业负责人"
            show-overflow-tooltip
            prop="professional_leader"
          >
            <template #default="scope">
              <el-tag
                style="margin-right: 5px"
                v-if="scope.row.professional_leader.length > 0"
                v-for="(item, index) in scope.row.professional_leader"
                :key="index"
                size="small"
                class="ml-2"
                type="success"
              >
                {{ item || "未指定" }}
              </el-tag>
              <el-tag v-else size="small" class="ml-2" type="danger">
                未指定
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            width="120"
            label="责任组长"
            show-overflow-tooltip
            prop="professional_leader"
          >
            <template #default="scope">
              <el-tag
                style="margin-right: 5px"
                v-if="scope.row.team_leader.length > 0"
                v-for="(item, index) in scope.row.team_leader"
                :key="index"
                size="small"
                class="ml-2"
                type="success"
              >
                {{ item || "未指定" }}
              </el-tag>
              <el-tag v-else size="small" class="ml-2" type="danger">
                未指定
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="项目状态"
            show-overflow-tooltip
            prop="proState"
          >
            <template #header>
              <div style="display: flex;align-items: center;">
            <div style="margin-right: 5px;">项目状态 </div>
            <el-popover :width="200" trigger="hover">
              <template #reference>
                <div class="icone" :class="proState_choose.length == 0 ? '' : 'active'">
                  <el-icon>
                    <Filter />
                  </el-icon>
                </div>
              </template>
              <el-select-v2 :teleported='false' size="small" style="width: 180px; margin-right: 10px;z-index: 2000;"
                clearable multiple filterable collapse-tags collapse-tags-tooltip :options="[
                  {
                    value: '运行中',

                    label: '运行中'
                  },
                  {
                    value: '已关闭',

                    label: '已关闭'
                  },
                  {
                    value: '已删除',

                    label: '已删除'
                  },



                ]" v-model="proState_choose"  placeholder="请选择">
              </el-select-v2>

            </el-popover>
          </div>
          </template>
            <template #default="scope">
              <div
                v-if="scope.row.proj_status == '已关闭'"
                style="
                  display: inline-block;
                  height: 12px;
                  width: 12px;
                  background-color: #c1c1c1;
                  border-radius: 100% 100%;
                "
              ></div>
              <div
                v-if="scope.row.proj_status == '运行中'"
                style="
                  display: inline-block;
                  height: 12px;
                  width: 12px;
                  background-color: #67c23a;
                  border-radius: 100% 100%;
                "
              ></div>

              <div
                v-if="scope.row.proj_status == '已删除'"
                style="
                  display: inline-block;
                  height: 12px;
                  width: 12px;
                  background-color: #faad14;
                  border-radius: 100% 100%;
                "
              ></div>

              <span style="font-size: 14px; color: #707070">
                &nbsp;{{ scope.row.proj_status }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            label="开始时间"
            show-overflow-tooltip
            prop="start_time"
          ></el-table-column>
          <el-table-column
            label="结束时间"
            show-overflow-tooltip
            prop="end_time"
          ></el-table-column>
          <el-table-column
            label="设计阶段"
            show-overflow-tooltip
            prop="design_stage"
          >
          <template #header>
              <div style="display: flex;align-items: center;">
            <div style="margin-right: 5px;">设计阶段 </div>
            <el-popover :width="200" trigger="hover">
              <template #reference>
                <div class="icone" :class="design_stage_choose.length == 0 ? '' : 'active'">
                  <el-icon>
                    <Filter />
                  </el-icon>
                </div>
              </template>
              <el-select-v2 :teleported='false' size="small" style="width: 180px; margin-right: 10px;z-index: 2000;"
                clearable multiple filterable collapse-tags collapse-tags-tooltip :options="[
                {
                  value: '详细设计',
                  label: '详细设计',
                },
                {
                  value: '基础设计',
                  label: '基础设计',
                },
                {
                  value: '可行性研究',
                  label: '可行性研究',
                },
                {
                  value: '报价项目',
                  label: '报价项目',
                },
                {
                  value: '技术创新课题',
                  label: '技术创新课题',
                },
              ]" v-model="design_stage_choose"  placeholder="请选择">
              </el-select-v2>

            </el-popover>
          </div>
          </template>
        </el-table-column>
          <el-table-column width="200" show-overflow-tooltip label="操作">
            <template #default="scope">
              <span
              v-if='AUTH_'
                style="
                  color: #1890ff;
                  margin-left: 1em;
                  font-size: 12px;
                  cursor: pointer;
                "
                size="small"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</span
              >
              <el-popconfirm
                title="确定要删除了?"
                @confirm="handleEditRe(scope.$index, scope.row, '已删除')"
              >
                <template #reference>
                  <span
                    style="
                      color: #f56c6c;
                      font-size: 12px;
                      cursor: pointer;
                      margin-left: 1em;
                    "
                    >删除</span
                  >
                </template>
              </el-popconfirm>
              <span
                style="
                  color: rgb(103, 194, 58);
                  margin-left: 1em;
                  font-size: 12px;
                  cursor: pointer;
                "
                size="small"
                @click="handleEditRe(scope.$index, scope.row, '运行中')"
                >重启</span
              >
              <span
                style="
                  color: rgb(250, 173, 20);
                  margin-left: 1em;
                  font-size: 12px;
                  cursor: pointer;
                "
                size="small"
                @click="handleEditRe(scope.$index, scope.row, '已关闭')"
                >关闭</span
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-dialog
      draggable
      v-model="dialogVisibleNew"
      :destroy-on-close="true"
      title="新建项目"
      width="28%"
      :before-close="() => handleClose(ruleFormRefNew)"
    >
      <el-form
        ref="ruleFormRefNew"
        :model="ruleFormNew"
        :rules="rulesNew"
        size="small"
        label-width="130"
        class="demo-ruleForm-new"
      >
        <el-form-item label="项目代号：" prop="proj_no">
          <el-input
            v-model="ruleFormNew.proj_no"
            placeholder="请输入项目代号"
          />
        </el-form-item>
        <el-form-item label="项目名称：" prop="proj_name">
          <el-input
            v-model="ruleFormNew.proj_name"
            placeholder="请输入项目名称"
          />
        </el-form-item>
        <el-form-item v-if="false" label="项目状态：" prop="proj_status">
          <el-select
            disabled
            style="width: 100%"
            v-model="ruleFormNew.proj_status"
            class="bpmn_select"
            placeholder="请选择项目状态"
          >
            <el-option
              v-for="item in [
                { value: '运行中', label: '运行中' },
                { value: '已关闭', label: '已关闭' },
                { value: '已删除', label: '已删除' },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="专业负责人：" prop="professional_leader">
          <el-select
            :filter-method="matchFruit"
            multiple
            clearable
            style="width: 100%"
            v-model="ruleFormNew.professional_leader"
            collapse-tags
            collapse-tags-tooltip
            placeholder="请选择专业负责人"
            filterable
          >
            <el-option
              v-for="(item, index) in list_filtered"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="责任组长：" prop="team_leader">
          <el-select
            :filter-method="matchFruit"
            multiple
            clearable
            style="width: 100%"
            v-model="ruleFormNew.team_leader"
            placeholder="请选择责任组长"
            filterable
          >
            <el-option
              v-for="item in list_filtered"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目起始时间：" prop="date">
          <el-date-picker
            v-model="ruleFormNew.date"
            type="daterange"
            range-separator=" - "
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item label="设计阶段" prop="design_stage">
          <el-select
            style="width: 100%"
            placeholder="请选择设计阶段"
            v-model="ruleFormNew.design_stage"
            filterable
          >
            <el-option
              v-for="(item, index) in [
                {
                  value: '详细设计',
                  label: '详细设计',
                },
                {
                  value: '基础设计',
                  label: '基础设计',
                },
                {
                  value: '可行性研究',
                  label: '可行性研究',
                },
                {
                  value: '报价项目',
                  label: '报价项目',
                },
                {
                  value: '技术创新课题',
                  label: '技术创新课题',
                },
              ]"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <div class="button_footer">
            <el-button
              @click="
                () => {
                  dialogVisibleNew = false;
                  ruleFormNew.date = null;
                }
              "
              >取消</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button v-debounce type="primary" @click="submitFormNew(ruleFormRefNew)"
              >确认</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      draggable
      v-model="dialogVisibleEdit"
      :destroy-on-close="true"
      title="编辑项目"
      width="28%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit"
        :model="ruleFormEdit"
        :rules="rulesNew"
        label-width="130px"
        class="demo-ruleForm-Edit"
      >
        <el-form-item label="项目编号：" prop="proj_no">
          <el-input
            size="small"
            disabled
            v-model="ruleFormEdit.proj_no"
            placeholder="请输入项目代号"
          />
        </el-form-item>
        <el-form-item label="项目名称：" prop="proj_name">
          <el-input
            size="small"
            disabled
            v-model="ruleFormEdit.proj_name"
            placeholder="请输入项目名称"
          />
        </el-form-item>
        <el-form-item v-if="false" label="项目状态：" prop="proj_status">
          <el-select
            style="width: 100%"
            size="small"
            filterable
            v-model="ruleFormEdit.proj_status"
            class="bpmn_select"
            placeholder="请选择项目状态"
          >
            <el-option
              v-for="item in [
                {
                  value: '运行中',
                  label: '运行中',
                },
                {
                  value: '已关闭',
                  label: '已关闭',
                },
                {
                  value: '已删除',
                  label: '已删除',
                },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="专业负责人：" prop="professional_leader">
          <el-select
            :filter-method="matchFruit"
            multiple
            clearable
            size="small"
            style="width: 100%"
            v-model="ruleFormEdit.professional_leader"
            placeholder="请选择专业负责人"
            filterable
          >
            <el-option
              v-for="item in list_filtered"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="责任组长：" prop="team_leader">
          <el-select
            :filter-method="matchFruit"
            multiple
            clearable
            size="small"
            style="width: 100%"
            v-model="ruleFormEdit.team_leader"
            filterable
            placeholder="请选择责任组长"
          >
            <el-option
              v-for="(item, index) in list_filtered"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="项目起始时间：" prop="date">
          <el-date-picker
            size="small"
            v-model="ruleFormEdit.date"
            type="daterange"
            range-separator=" - "
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item label="设计阶段" prop="design_stage">
          <el-select
            style="width: 100%"
            placeholder="请选择设计阶段"
            v-model="ruleFormEdit.design_stage"
            filterable
          >
            <el-option
              v-for="(item, index) in [
                {
                  value: '详细设计',
                  label: '详细设计',
                },
                {
                  value: '基础设计',
                  label: '基础设计',
                },
                {
                  value: '可行性研究',
                  label: '可行性研究',
                },
                {
                  value: '报价项目',
                  label: '报价项目',
                },
                {
                  value: '技术创新课题',
                  label: '技术创新课题',
                },
              ]"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <div class="button_footer">
            <el-button @click="dialogVisibleEdit = false">取消</el-button>
            &nbsp;&nbsp;&nbsp;
            <el-button v-debounce type="primary" @click="submitFormEdit(ruleFormRefEdit)"
              >确认</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      size="small"
      draggable
      v-model="dialogVisibleEdit2"
      :destroy-on-close="true"
      title="编辑主项"
      width="23%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit2"
        :model="ruleFormEdit2"
        :rules="rulesNew3"
        label-width="80px"
        class="demo-ruleForm-Edit"
        status-icon
      >
        <el-form-item label="主项号：" prop="unit_no">
          <el-input
            size="small"
            v-model="ruleFormEdit2.unit_no"
            placeholder="请输入主项号"
          />
        </el-form-item>
        <el-form-item label="主项名：" prop="unit_name">
          <el-input
            size="small"
            v-model="ruleFormEdit2.unit_name"
            placeholder="请输入主项名称"
          />
        </el-form-item>
        <el-form-item label="备注：" prop="note">
          <el-input
            size="small"
            v-model="ruleFormEdit2.note"
            placeholder="请输入备注"
          />
        </el-form-item>
        <el-form-item>
          <div class="button_footer">
            <el-button
              size="small"
              type="primary"
              @click="submitFormEdit2(ruleFormRefEdit2)"
              >修改</el-button
            >
            &nbsp; &nbsp; &nbsp;
            <el-button size="small" @click="resetFormEdit2(ruleFormRefEdit2)"
              >取消</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      size="small"
      draggable
      v-model="dialogVisibleEdit3"
      :destroy-on-close="true"
      :before-close="() => resetFormEdit3(ruleFormRefEdit3)"
      title="新增主项"
      width="23%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit3"
        :model="ruleFormEdit3"
        :rules="rulesNew2"
        label-width="80px"
        class="demo-ruleForm-Edit"
        status-icon
      >
        <el-form-item label="主项号：" prop="proSubcode">
          <el-input
            size="small"
            v-model="ruleFormEdit3.proSubcode"
            placeholder="请输入主项号"
          />
        </el-form-item>
        <el-form-item label="主项名：" prop="proSubname">
          <el-input
            size="small"
            v-model="ruleFormEdit3.proSubname"
            placeholder="请输入主项名称"
          />
        </el-form-item>
        <el-form-item label="备注：" prop="proRemark">
          <el-input
            size="small"
            v-model="ruleFormEdit3.proRemark"
            placeholder="请输入备注"
          />
        </el-form-item>
        <el-form-item>
          <div class="button_footer">
            <el-button
              size="small"
              type="primary"
              @click="submitFormEdit3(ruleFormRefEdit3)"
              >新增</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button size="small" @click="resetFormEdit3(ruleFormRefEdit3)"
              >取消</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      size="small"
      draggable
      v-model="dialogVisibleEdit3Notice"
      :destroy-on-close="true"
      :before-close="() => resetFormEdit3Notice(ruleFormRefEdit3Notice)"
      title="公告撰写"
      width="23%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit3Notice"
        :model="ruleFormEdit3Notice"
        :rules="rulesNew2Notice"
        label-width="80px"
        class="demo-ruleForm-Edit"
        status-icon
      >
        <el-form-item label="公告内容：" prop="proSubcode">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 16 }"
            size="small"
            v-model="ruleFormEdit3Notice.content"
            placeholder="请输入公告内容"
          />
        </el-form-item>

        <el-form-item>
          <div class="button_footer">
            <el-button
              size="small"
              type="primary"
              @click="submitFormEdit3Notice(ruleFormRefEdit3Notice)"
              >新增</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button
              size="small"
              @click="resetFormEdit3Notice(ruleFormRefEdit3Notice)"
              >取消</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      size="small"
      draggable
      v-model="dialogVisibleEdit3User"
      :destroy-on-close="true"
      :before-close="() => resetFormEdit3User(ruleFormRefEdit3User)"
      title="新增用户"
      width="23%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit3User"
        :model="ruleFormEdit3User"
        :rules="rulesNew2User"
        label-width="90px"
        class="demo-ruleForm-Edit"
      >
        <el-form-item label="角色名称：" prop="role_name">
          <el-select
            clearable
            style="width: 100%"
            size="small"
            filterable
            placeholder="请选择角色名称"
            v-model="ruleFormEdit3User.role_name"
          >
            <el-option
              v-for="(item, index) in roleOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="参与人员：" prop="name">
          <el-select
            clearable
            :filter-method="matchFruit"
            multiple
            collapse-tags
            collapse-tags-tooltip
            style="width: 100%"
            size="small"
            filterable
            placeholder="请选择参与人员"
            v-model="ruleFormEdit3User.name"
          >
            <el-option
              v-for="(item, index) in list_filtered"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <div class="button_footer">
            <el-button
              size="small"
              type="primary"
              @click="submitFormEdit3User(ruleFormRefEdit3User)"
              >新增</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button
              size="small"
              @click="resetFormEdit3User(ruleFormRefEdit3User)"
              >取消</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      size="small"
      draggable
      v-model="dialogVisibleEditUser"
      :destroy-on-close="true"
      :before-close="() => resetFormEdit3Users(ruleFormRefEdit3Users)"
      title="编辑用户"
      width="23%"
    >
      <el-form
        size="small"
        ref="ruleFormRefEdit3Users"
        :model="ruleFormEditUser"
        :rules="rulesNew2User"
        label-width="90px"
        class="demo-ruleForm-Edit"
      >
        <el-form-item label="角色名称：" prop="role_name">
          <el-select
            disabled
            style="width: 100%"
            size="small"
            filterable
            placeholder="请选择角色名称"
            v-model="ruleFormEditUser.role_name"
          >
            <el-option
              v-for="(item, index) in roleOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="参与人员：" prop="name">
          <el-select
            clearable
            :filter-method="matchFruit"
            multiple
            collapse-tags
            collapse-tags-tooltip
            style="width: 100%"
            size="small"
            filterable
            placeholder="请选择参与人员"
            v-model="ruleFormEditUser.name"
          >
            <el-option
              v-for="(item, index) in list_filtered"
              :key="index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <div class="button_footer">
            <el-button
              size="small"
              type="primary"
              @click="submitFormEdit3Users(ruleFormRefEdit3Users)"
              >确认</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button
              size="small"
              @click="resetFormEdit3Users(ruleFormRefEdit3Users)"
              >取消</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup name="systemRole">
  import { Filter} from "@element-plus/icons-vue";
import { defineAsyncComponent, reactive, onMounted, ref, watch } from "vue";
import { ElMessageBox, ElMessage,ElLoading } from "element-plus";
import {
  Search,
  CirclePlus,
  Upload,
  Download,
  Delete,
} from "@element-plus/icons-vue";
import { useProjectStore } from "../../stores/project";
import { storeToRefs } from "pinia";
import {
  isunitUsed,
  DeleteUnit,
  ModifyUnit,
  AddUnit,
  AddProjectUserV2,
  DeleteUserV2,
  GetUnits,
  deleteproject,
  modifyprojectstatus,
  ModifyProjectInfoV2,
  AddProjectV2,
  impMarjor,
  getPro,
  AddNewProjectNotice,
  getMarjorPro,
  getOptionLeader,
  getOptionTeam,
  delPro,
  delMarjorTable,
  GetProjectUnifiedRegulationFiles,
  UploadProjectUnifiedRegulationFiles,
  DownloadProjectUnifiedRegulationFile,
  DeleteProjectUnifiedRegulationFile,
  AddProjectNotice,
  ModifyProjectNoticeState,
  GetAllProjectNotices,
  GetProjectUsers,
  GetDepartmentUsersV2,
  GetRoles,
  DownloadProjectUnitsLoadTemp,
  GetProjBasicDesignData,
  SaveProjBasicDesignData,
} from "../../api/projectManage/projectList";
import PinYinMatch from "pinyin-match";
let store = useProjectStore();

let list_filtered = ref([]);
let matchFruit = (searchContent) => {
  if (searchContent) {
    let result = [];
    personOptions.value.forEach((item) => {
      // matchResult 的值为 true/false
      let matchResult = PinYinMatch.match(item.label, searchContent);
      if (matchResult) {
        result.push(item);
      }
    });
    list_filtered.value = result;
  } else {
    list_filtered.value = personOptions.value;
  }
};

let personOptions_PINGYING = ref([]);
let matchProfessional = (searchContent) => {
  if (searchContent) {
    let result = [];
    personOptions.value.forEach((item) => {
      // matchResult 的值为 true/false
      let matchResult = PinYinMatch.match(item.label, searchContent);
      if (matchResult) {
        result.push(item);
      }
    });

    personOptions_PINGYING.value = result;
  } else {
    personOptions_PINGYING.value = personOptions.value;
  }
};

let { projectInfo } = storeToRefs(store);

let proName = ref("");
let strProName
watch(proName, async () => {
  if (proName.value) {
    strProName = proName.value
    // design_stage_choose.value =[]
    // proState_choose.value =[]
    let res = await getPro({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
    });
    res.forEach((item) => {
      if (item.create_time) {
        // 清理日期字符串并转换为标准格式
        item.create_time = item.time = item.create_time.replace(/\D/g, "");
      } else {
        // 如果时间是null，分配一个非常小的值以确保它在排序时排在最后
        item.create_time = -Infinity;
      }
    });

    res.sort((a, b) => {
      // 如果两个元素都不是null，比较它们的日期，将最新的日期排在前面
      return b.create_time - a.create_time;
    });
    let data = JSON.parse(JSON.stringify(res));
    tableDataPro.value = data
      .filter(
        (v) =>
          v.proj_name.toLowerCase().includes(proName.value.toLowerCase()) ||
          v.proj_no.toLowerCase().includes(proName.value.toLowerCase())
      )
      .map((v) => {
        return {
          ...v,
          professional_leader:
            v.professional_leader && v.professional_leader.indexOf(",")
              ? v.professional_leader.split(",")
              : [],
          team_leader:
            v.team_leader && v.team_leader.indexOf(",")
              ? v.team_leader.split(",")
              : [],
        };
      });
    
  } else {

   
    getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);


  }
});


let proState_choose = ref([])
let design_stage_choose = ref([])
watch([proState_choose,design_stage_choose],()=>{
 if(proState_choose.value.length>0 || proState_choose.value.length>0){
  getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);
 }else{
  getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);
 }
  
})


let getProTable = async (data,proState=[],design_stage=[]) => {
  let res = await getPro(data);
  res.forEach((item) => {
    if (item.create_time) {
      // 清理日期字符串并转换为标准格式
      item.create_time = item.time = item.create_time.replace(/\D/g, "");
    } else {
      // 如果时间是null，分配一个非常小的值以确保它在排序时排在最后
      item.create_time = -Infinity;
    }
  });

  res.sort((a, b) => {
    // 如果两个元素都不是null，比较它们的日期，将最新的日期排在前面
    return b.create_time - a.create_time;
  });
  
  tableDataPro.value = res.map((v) => {
    return {
      ...v,
      professional_leader:
        v.professional_leader && v.professional_leader.indexOf(",")
          ? v.professional_leader.split(",")
          : [],
      team_leader:
        v.team_leader && v.team_leader.indexOf(",")
          ? v.team_leader.split(",")
          : [],
    };
  });
    // 定义筛选条件
    const filters = {
      proj_status:proState,
      design_stage:design_stage
  };
  let datas = multiFilter(JSON.parse(JSON.stringify(tableDataPro.value)), filters)

  tableDataPro.value = datas
  return tableDataPro.value;
};


function multiFilter(array, filters) {

  const filterKeys = Object.keys(filters);

  return array.filter((item) => {
    return filterKeys.every((key) => {
      if (!filters[key].length) return true;
      return !!~filters[key].indexOf(item[key]);
    });
  });
}

let submitFormEdit3 = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      let obj = {
        proj_oid: proData.value.proj_oid,
        unit_no: ruleFormEdit3.value.proSubcode,
        unit_name: ruleFormEdit3.value.proSubname,
        note: ruleFormEdit3.value.proRemark,
      };
      let res = await AddUnit(obj);
      console.log(res);
      if (res === true) {
        ElMessage({
          message: "新增成功",
          type: "success",
        });
        getMarjorProData({ proj_oid: proData.value.proj_oid });
        dialogVisibleEdit3.value = false;
        ruleFormEdit3.value.proSubcode = "";
        ruleFormEdit3.value.proSubname = "";
        ruleFormEdit3.value.proRemark = "";
      } else if (res.data == "新增主项已存在！") {
        ElMessage({
          message: res.data,
          type: "error",
        });
      } else {
        ElMessage({
          message: "新增失败",
          type: "error",
        });
      }
    }
  });
};

let submitFormEdit3User = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      let resRole = await GetRoles();
      let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
      let user_permission = resRole.filter(
        (v) => v.role_name == ruleFormEdit3User.value.role_name
      )[0].role_auth_code;
      let users = ruleFormEdit3User.value.name.map((v) => {
        return {
          ...resPerson.find((item) => item.account_id === v),
          user_permission: user_permission,
          user_account: resPerson.find((item) => item.account_id === v)
            .login_account,
        };
      });

      let obj = {
        proj_oid: proData.value.proj_oid,
        user_role: ruleFormEdit3User.value.role_name,
        users: users,
      };

      await AddProjectUserV2(obj);
      ElMessage({
        message: "新增成功",
        type: "success",
      });
      ruleFormRefEdit3User.value.resetFields();
      dialogVisibleEdit3User.value = false;
      getUserAllData();
    }
  });
};

let submitFormEdit3Users = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      let resRole = await GetRoles();
      let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
      let user_permission = resRole.filter(
        (v) => v.role_name == ruleFormEditUser.value.role_name
      )[0].role_auth_code;
      let users = ruleFormEditUser.value.name.map((v) => {
        return {
          ...resPerson.find((item) => item.user_name === v),
          user_permission: user_permission,
          user_account: resPerson.find((item) => item.user_name === v)
            .login_account,
        };
      });

      let obj = {
        proj_oid: proData.value.proj_oid,
        user_role: ruleFormEditUser.value.role_name,
        users: users,
      };

      await AddProjectUserV2(obj);
      ElMessage({
        message: "修改成功",
        type: "success",
      });
      getUserAllData();
      dialogVisibleEditUser.value = false;
    }
  });
};

let submitFormEdit3Notice = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      let obj;

      if (editNotice.value) {
        obj = {
          ...ruleFormEdit3Notice.value,
          id: ruleFormEdit3Notice.value.Id,
        };
      } else {
        obj = {
          proj_oid: proData.value.proj_oid,
          content: ruleFormEdit3Notice.value.content,
          state: "已发布",
        };
      }
      editNotice.value = false;
      await AddProjectNotice(obj);
      ElMessage({
        message: "编写成功",
        type: "success",
      });
      getNotice({ proj_oid: proData.value.proj_oid });
      dialogVisibleEdit3Notice.value = false;
    }
  });
};

let uploadExcel = async (uploadFile) => {
  let formData = new FormData();
  //传给后台接收的名字 file
  formData.append("file", uploadFile.file);
  await impMarjor(formData, proData.value.proj_oid);
  ElMessage({
    message: "导入成功",
    type: "success",
  });

  getMarjorProData({ proj_oid: proData.value.proj_oid });
};

let resetFormEdit3 = (formEl) => {
  if (!formEl) return;
  dialogVisibleEdit3.value = false;
  formEl.resetFields();
};

let resetFormEdit3User = (formEl) => {
  if (!formEl) return;
  dialogVisibleEdit3User.value = false;
  formEl.resetFields();
};

let resetFormEdit3Users = (formEl) => {
  if (!formEl) return;
  dialogVisibleEditUser.value = false;
  formEl.resetFields();
};

let ruleFormRefEdit3Notice = ref("");
let resetFormEdit3Notice = (formEl) => {
  if (!formEl) return;
  dialogVisibleEdit3Notice.value = false;
  formEl.resetFields();
};

let delArr = ref([]);
let delAll = async () => {
  if (delArr.value.length == 0) {
    ElMessage({ message: "请选择要删除的项目", type: "error" });
    return;
  }

  delArr.value.forEach(async (v, i) => {
    await DeleteUnit({ ...v });
    if (i == delArr.value.length - 1) {
      ElMessage({
        message: "批量删除成功",
        type: "success",
      });
      getMarjorProData({ proj_oid: proData.value.proj_oid });
    }
  });
};

let confirmEvent2 = async (index, row) => {
  try {
    let res = await isunitUsed({ unit_oid: row.unit_oid });

    if (res.data == "True") {
      ElMessage({
        message:
          "该主项已经被设备占用无法删除，请去设备管理页面中解绑后才可删除",
        type: "error",
      });
    } else {
      await DeleteUnit({
        unit_oid: row.unit_oid,
      });
      getMarjorProData({ proj_oid: proData.value.proj_oid });
      ElMessage({
        message: "删除成功",
        type: "success",
      });
    }
  } catch (error) {
    if (error.toString().includes("False")) {
      await DeleteUnit({
        unit_oid: row.unit_oid,
      });
      getMarjorProData({ proj_oid: proData.value.proj_oid });

      ElMessage({
        message: "删除成功",
        type: "success",
      });
    }
  }
};

let confirmEvent2User = async (index, row) => {
  if (row.person.length > 0) {
    row.person.forEach(async (v, i) => {
      await DeleteUserV2({
        user_oid: v.user_oid,
      });

      if (row.person.length - 1 == i) {
        getUserAllData();
        ElMessage({
          message: "删除成功",
          type: "success",
        });
      }
    });
  }
};

let tableRuleData = ref([]);

let gettableRuleDataData = async (data) => {
  let res = await GetProjectUnifiedRegulationFiles(data);

  tableRuleData.value = res;
};

let tableRuleData2 = ref([]);
let gettableRuleDataData2 = async (data) => {
  let res = await GetProjectUnifiedRegulationFiles(data);

  tableRuleData2.value = res;
};

let ruleFormRefEdit3 = ref("");
let dialogVisibleEdit3 = ref(false);
let addNEWpro = () => {
  dialogVisibleEdit3.value = true;
};

let downloadTemplate = async () => {
  let res = await DownloadProjectUnitsLoadTemp();
  let filename = res.headers; //下载后文件名
  let filename2 = ""; //下载后文件名
  filename = filename["content-disposition"];
  filename = window.decodeURI(filename);
  filename2 = filename.split(";")[1].split("filename*=UTF-8''")[1];
  filename = filename.split(";")[1].split("filename=")[1];
  const link = document.createElement("a"); // 创建a标签
  const blo = new Blob([res.data], { type: res.data.type }); // 设置下载格式
  link.style.display = "none";
  const url = window.URL.createObjectURL(blo);
  console.log(url);
  link.href = url;
  if (filename == undefined) {
    filename = filename2;
  }
  link.download = filename;

  // link.setAttribute('download', "fileName")3
  document.body.appendChild(link);
  link.click(); // 触发下载
  window.URL.revokeObjectURL(url); // 释放掉blob对象
  document.body.removeChild(link);
};

let dialogVisibleEdit3User = ref(false);
let roleOptions = ref([]);
let personOptions = ref([]);
let addNEWproUser = async () => {
  let resRole = await GetRoles();
  let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
  personOptions.value = resPerson.map((v) => {
    return {
      value: v.account_id,
      label: v.user_name,
    };
  });
  list_filtered.value = personOptions.value;
  personOptions_PINGYING = personOptions.value;
  roleOptions.value = resRole
    .filter((v) => v.role_auth_code <= 40 && v.role_name !== "初始用户")
    .map((v) => {
      return {
        value: v.role_name,
        label: v.role_name,
      };
    })
    .reverse();

  let flag = [];
  if (userTable.value.length > 0) {
    roleOptions.value.forEach((v) => {
      flag = flag.concat(
        userTable.value.filter((item) => item.user_role == v.value)
      );
    });
    let flagMap = flag.map((v) => v.user_role);

    flagMap.forEach((v) => {
      roleOptions.value.forEach((item, index) => {
        if (item.value == v) {
          roleOptions.value.splice(index, 1);
        }
      });
    });
  }

  dialogVisibleEdit3User.value = true;
};

let dialogVisibleEdit3Notice = ref(false);
let editNotice = ref(false);
let addNEWproNotice = (row) => {
  if (!row.isTrusted) {
    editNotice.value = true;
    ruleFormEdit3Notice.value = { ...row };
  } else {
    ruleFormEdit3Notice.value.content = "";
    editNotice.value = false;
  }

  dialogVisibleEdit3Notice.value = true;
};

let addNEWproNoticeF = async (str, row) => {
  if (str == "已发布") {
    await ModifyProjectNoticeState({ ...row, state: "已发布", id: row.Id });
  } else if (str == "未发布") {
    await ModifyProjectNoticeState({ ...row, state: "未发布", id: row.Id });
  } else if ((str = "已删除")) {
    await ModifyProjectNoticeState({ ...row, state: "已删除", id: row.Id });
  }
  ElMessage({
    message: "状态修改成功",
    type: "success",
  });
  getNotice({ proj_oid: proData.value.proj_oid });
};

let ruleFormRefEdit3User = ref();
let ruleFormEdit3User = ref({
  role_name: "",
  name: [],
});
let rulesNew2User = ref({
  role_name: [{ required: true, message: "请选择角色名称", trigger: "change" }],
  name: [{ required: true, message: "请选择人员", trigger: "change" }],
});

let ruleFormEdit3 = ref({
  proSubcode: "",
  proSubname: "",
  proRemark: "",
});

let ruleFormEdit3Notice = ref({
  content: "",
});

let handleSelectionChange = (val) => {
  delArr.value = val.map((item) => {
    return item;
  });
};

let dialogVisibleEdit2 = ref(false);
let ruleFormEdit2 = ref({});
let handleEdit2 = (index, item) => {
  dialogVisibleEdit2.value = true;
  ruleFormEdit2.value = { ...item };
};

let convertFileSize =(sizeInBytes) => {
  
  if (sizeInBytes >= 100000) {
      // 如果文件大小大于或等于100KB，则转换为MB
      return (sizeInBytes / (1024 * 1024)).toFixed(2) + ' MB';
  } else {
      // 如果文件大小小于100KB，则保留为KB
      return (sizeInBytes / 1024).toFixed(2) + ' KB';
  }
}

let ruleFormRefEdit3Users = ref("");
let dialogVisibleEditUser = ref(false);
let ruleFormEditUser = ref({});
let handleEdit2User = async (index, item) => {
  let resRole = await GetRoles();
  let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });

  personOptions.value = resPerson.map((v) => {
    return {
      value: v.user_name,
      label: v.user_name,
    };
  });
  list_filtered.value = personOptions.value;
  personOptions_PINGYING = personOptions.value;
  roleOptions.value = resRole
    .filter((v) => v.role_auth_code <= 40)
    .map((v) => {
      return {
        value: v.role_name,
        label: v.role_name,
      };
    })
    .reverse();

  dialogVisibleEditUser.value = true;

  ruleFormEditUser.value = {
    ...item,
    role_name: item.user_role,
    name: item.person.map((v) => v.user_name),
  };
};

let rulesNew2 = ref({
  proRemark: [{ required: false, message: "请输入描述", trigger: "blur" }],
  proSubname: [{ required: true, message: "请输入主项名称", trigger: "blur" }],
  proSubcode: [{ required: true, message: "请输入主项号", trigger: "blur" }],
});

let rulesNew2Notice = ref({
  content: [{ required: true, message: "请输入公告内容", trigger: "blur" }],
});

let rulesNew3 = ref({
  note: [{ required: false, message: "请输入描述", trigger: "blur" }],
  unit_name: [{ required: true, message: "请输入主项名称", trigger: "blur" }],
  unit_no: [{ required: true, message: "请输入主项号", trigger: "blur" }],
});

let confirmEvent = async (index, item) => {
  await delPro({});
  ElMessage({ type: "success", message: "删除成功" });
  getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);
};

let submitFormEdit = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      ruleFormEdit.value.start_time = ruleFormEdit.value.date[0];
      ruleFormEdit.value.end_time = ruleFormEdit.value.date[1];

      let resRole = await GetRoles();
      let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
      let professional_leaders_Role = resRole.filter(
        (v) => v.role_name == "专业负责人"
      )[0].role_auth_code;

      let professional_leaders = ruleFormEdit.value.professional_leader?.map(
        (v) => {
          return {
            ...resPerson.find((item) => item.user_name === v),
            user_permission: professional_leaders_Role,
            user_account: resPerson.find((item) => item.user_name === v)
              .login_account,
          };
        }
      );

      let team_leaders_Role = resRole.filter(
        (v) => v.role_name == "专业组长"
      )[0].role_auth_code;
      let team_leaders = ruleFormEdit.value.team_leader?.map((v) => {
        return {
          ...resPerson.find((item) => item.user_name === v),
          user_account: resPerson.find((item) => item.user_name === v)
            .login_account,
          user_permission: team_leaders_Role,
        };
      });

      let obj = {
        ...ruleFormEdit.value,
        professional_leaders: professional_leaders || [],
        team_leaders: team_leaders || [],
      };

      await ModifyProjectInfoV2({
        ...obj,
        user_name:JSON.parse(
      localStorage.getItem("userMessage")
    ).user_name
      });
      getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);
      ElMessage({
        message: "添加成功",
        type: "success",
      });
      proName.value= ''
      const loading = ElLoading.service({
    lock: true,
    text: '正在执行，请稍等...',
    background: 'rgba(255,255, 255, 0.9)',
  })
  setTimeout(()=>{
    proName.value = strProName
    setTimeout(()=>{
      loading.close()
    },2000)
  },30)
      dialogVisibleEdit.value = false;
    }
  });
};

let tableDataPro = ref([]);
let ruleFormRefEdit = ref("");
let dialogVisibleEdit = ref(false);
let ruleFormEdit = ref({});
let handleEdit = async (index, item) => {
  dialogVisibleEdit.value = true;
  let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
  personOptions.value = resPerson.map((v) => {
    return {
      value: v.user_name,
      label: v.user_name,
    };
  });
  list_filtered.value = personOptions.value;
  personOptions_PINGYING = personOptions.value;
  ruleFormEdit.value = { ...item };

  if (!ruleFormEdit.value.professional_leader[0]) {
    ruleFormEdit.value.professional_leader = [];
  }
  if (!ruleFormEdit.value.team_leader[0]) {
    ruleFormEdit.value.team_leader = [];
  }

  ruleFormEdit.value.date = [item.start_time, item.end_time];
};
let getOptions = async (data) => {
  let option1 = await getOptionTeam(data);
  let option2 = await getOptionLeader(data);
  userOptionsleader.value = option2;
  optionsNewteam_leader.value = option1;
};

let ruleFormRefEdit2 = ref("");
let submitFormEdit2 = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      await ModifyUnit({
        ...ruleFormEdit2.value,
        proj_oid: proData.value.proj_oid,
      });

      ElMessage({
        message: "修改成功",
        type: "success",
      });
      dialogVisibleEdit2.value = false;
      getMarjorProData({ proj_oid: proData.value.proj_oid });
    }
  });
};

let delArrRule = ref([]);
let handleSelectionChangeRule = (val) => {
  delArrRule.value = val.map((item) => {
    return item.Id;
  });
};

let resetFormEdit2 = (formEl) => {
  if (!formEl) return;
  dialogVisibleEdit2.value = false;
  formEl.resetFields();
};

watch(
  projectInfo,
  () => {
    if (projectInfo.value && Object.keys(projectInfo.value).length > 0) {
      getOptions({});
      getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);
    }
  },
  { immediate: true }
);

let handleClose = (refsd) => {
  dialogVisibleNew.value = false;
  refsd.resetFields();
  ruleFormNew.value.date = null;
};

let rulesNew = ref({
  proj_no: [{ required: true, message: "请输入项目编号", trigger: "blur" }],
  proj_name: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
  professional_leader: [
    { required: false, message: "请选择专业负责人", trigger: "change" },
  ],
  team_leader: [{ required: false, message: "请选择组长", trigger: "change" }],
  proj_status: [
    { required: true, message: "请选择项目状态", trigger: "change" },
  ],
  date: [{ required: true, message: "请选择项目起始时间", trigger: "change" }],
  design_stage: [{ required: false, message: "请选择", trigger: "change" }],
});

let submitFormNew = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    if (valid) {
      ruleFormNew.value.start_time = ruleFormNew.value.date[0];
      ruleFormNew.value.end_time = ruleFormNew.value.date[1];

      let resRole = await GetRoles();
      let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
      let professional_leaders_Role = resRole.filter(
        (v) => v.role_name == "专业负责人"
      )[0].role_auth_code;
      let professional_leaders = ruleFormNew.value.professional_leader?.map(
        (v) => {
          return {
            ...resPerson.find((item) => item.account_id === v),
            user_permission: professional_leaders_Role,
            user_account: resPerson.find((item) => item.account_id === v)
              .login_account,
          };
        }
      );

      let team_leaders_Role = resRole.filter(
        (v) => v.role_name == "专业组长"
      )[0].role_auth_code;
      let team_leaders = ruleFormNew.value.team_leader?.map((v) => {
        return {
          ...resPerson.find((item) => item.account_id === v),
          user_account: resPerson.find((item) => item.account_id === v)
            .login_account,
          user_permission: team_leaders_Role,
        };
      });

      let obj = {
        ...ruleFormNew.value,
        professional_leaders: professional_leaders || [],
        team_leaders: team_leaders || [],
      };

      await AddProjectV2({
        ...obj,
        user_name:JSON.parse(
      localStorage.getItem("userMessage")
    ).user_name
      });
     let tableList = await getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);


      await AddNewProjectNotice({
        proj_oid:tableList[0].proj_oid,
        sendUser:JSON.parse(
      localStorage.getItem("userMessage")
    ).user_name
      })
   
      ElMessage({
        message: "添加成功",
        type: "success",
      });

      proName.value= ''
      const loading = ElLoading.service({
    lock: true,
    text: '正在执行，请稍等...',
    background: 'rgba(255,255, 255, 0.9)',
  })
  setTimeout(()=>{
    proName.value = strProName
    setTimeout(()=>{
      loading.close()
    },2000)
  },30)
      dialogVisibleNew.value = false;
      formEl.resetFields();
      ruleFormNew.value.date = null;
    }
  });
};

let previewRule = async (row) => {
  let res = await DownloadProjectUnifiedRegulationFile({
    remote_url: row.remote_url,
  });
  let filename = res.headers; //下载后文件名
  let filename2 = ""; //下载后文件名
  filename = filename["content-disposition"];
  filename = window.decodeURI(filename);
  filename2 = filename.split(";")[1].split("filename*=UTF-8''")[1];
  filename = filename.split(";")[1].split("filename=")[1];
  const link = document.createElement("a"); // 创建a标签
  const blo = new Blob([res.data], { type: res.data.type }); // 设置下载格式
  link.style.display = "none";
  const url = window.URL.createObjectURL(blo);
  link.href = url;
  if (filename == undefined) {
    filename = filename2;
  }
  link.download = filename;

  // link.setAttribute('download', "fileName")
  document.body.appendChild(link);
  link.click(); // 触发下载
  window.URL.revokeObjectURL(url); // 释放掉blob对象
  document.body.removeChild(link);
};

let delAllRules = async () => {
  delArrRule.value.forEach(async (v, i) => {
    await DeleteProjectUnifiedRegulationFile({ id: v });
    if (i == delArrRule.value.length - 1) {
      ElMessage({
        message: "删除成功",
        type: "success",
      });
      gettableRuleDataData({
        proj_oid: proData.value.proj_oid,
        file_type: "项目统一规定",
      });
      gettableRuleDataData2({
        proj_oid: proData.value.proj_oid,
        file_type: "设备联系单",
      });
    }
  });
};

let confirmDeleteRule = async (index, row) => {
  await DeleteProjectUnifiedRegulationFile({ ...row });
  ElMessage({
    message: "删除成功",
    type: "success",
  });
  gettableRuleDataData({
    proj_oid: proData.value.proj_oid,
    file_type: "项目统一规定",
  });
  gettableRuleDataData2({
    proj_oid: proData.value.proj_oid,
    file_type: "设备联系单",
  });
};
let uploadRequest = async (uploadFile) => {
  let formData = new FormData();
  //传给后台接收的名字 file
  formData.append("file", uploadFile.file);
  await UploadProjectUnifiedRegulationFiles(
    formData,
    proData.value.proj_oid,
    "项目统一规定"
  );
  ElMessage({
    message: "上传成功",
    type: "success",
  });
  gettableRuleDataData({
    proj_oid: proData.value.proj_oid,
    file_type: "项目统一规定",
  });
};

let uploadRequest2 = async (uploadFile) => {
  let formData = new FormData();
  //传给后台接收的名字 file
  formData.append("file", uploadFile.file);
  await UploadProjectUnifiedRegulationFiles(
    formData,
    proData.value.proj_oid,
    "设备联系单"
  );
  ElMessage({
    message: "上传成功",
    type: "success",
  });
  gettableRuleDataData2({
    proj_oid: proData.value.proj_oid,
    file_type: "设备联系单",
  });
};

let dataSData = ref([]);

let activeHeight = ref(0);

let expandArr = ref([]);
let tableTitleName = ref("主项管理");

let getMarjorProData = async (data) => {
  let res = await GetUnits(data);
  if (res) {
    dataSData.value = res;
  } else {
    dataSData.value = [];
  }
};

let handleEditRe = async (index, row, str) => {
  if (str === "已关闭") {
    await modifyprojectstatus({ proj_oid: row.proj_oid, proj_status: str });
  } else if (str === "运行中") {
    await modifyprojectstatus({ proj_oid: row.proj_oid, proj_status: str });
  } else if (str === "已删除") {
    await deleteproject({ proj_oid: row.proj_oid });
  }
  getProTable({
      user_token: localStorage.getItem("token"),
      authCode: localStorage.getItem("authCode"),
      
    },proState_choose.value,design_stage_choose.value);

  proName.value= ''
      const loading = ElLoading.service({
    lock: true,
    text: '正在执行，请稍等...',
    background: 'rgba(255,255, 255, 0.9)',
  })
  setTimeout(()=>{
    proName.value = strProName
    setTimeout(()=>{
      loading.close()
    },2000)
  },30)
  

  ElMessage({
    message: "状态修改成功",
    type: "success",
  });
};

let proData = ref({});

let dataFormRefNew = ref(null);

let submitDataFormNew = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid) => {
    dataForm.value.modify_user = JSON.parse(
      localStorage.getItem("userMessage")
    ).user_name;
    await SaveProjBasicDesignData({
      ...dataForm.value,
      proj_oid: proData.value.proj_oid,
    });
    ElMessage.success("添加成功");
  });
};

let expandChange = (expandedRows) => {
  proData.value = expandedRows;
  if (!expandArr.value.includes(expandedRows.proj_oid)) {
    expandArr.value = [];
    expandArr.value.push(expandedRows.proj_oid);
  } else {
    expandArr.value = [];
  }

  if (tableTitleName.value == "主项管理") {
    getMarjorProData({ proj_oid: proData.value.proj_oid });
  } else if (tableTitleName.value == "交付清单") {
  } else if (tableTitleName.value == "统一规定") {
    gettableRuleDataData({
      proj_oid: proData.value.proj_oid,
      file_type: "项目统一规定",
    });
  } else if (tableTitleName.value == "通知公告") {
    getNotice({ proj_oid: proData.value.proj_oid });
  } else if (tableTitleName.value == "设备联系单") {
    gettableRuleDataData2({
      proj_oid: proData.value.proj_oid,
      file_type: "设备联系单",
    });
  } else if (tableTitleName.value == "用户管理") {
    getUserAllData();
  } else if (tableTitleName.value == "设计基础数据") {
    getGetProjBasicDesignData();
  }
};

const tableSpanMethod = ({ rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    return {
      rowspan: spanTable(
        createSpanrowData(userTable.value, ["user_role"]),
        rowIndex
      ).rowspan,
      colspan: 1,
    };
  }
};

const spanTable = (spanArr, rowIndex) => {
  if (spanArr !== null && spanArr.length > 0) {
    for (let j = 0; j < spanArr.length; j++) {
      for (let i = 0; i < spanArr[j].spanLength; i++) {
        // 如果当前行是构造好的合并行数据的开始行，则返回rowspan:合并数据的合并行数量
        if (rowIndex === spanArr[j].fromIndex) {
          return {
            rowspan: spanArr[j].spanLength,
            colspan: 1,
          };
        } else if (
          rowIndex > spanArr[j].fromIndex &&
          rowIndex < spanArr[j].spanLength + spanArr[j].fromIndex
        ) {
          // 如果当前行大于构造好的合并行数据的开始行，小于合并行数据的开始行+合并数据的合并行数量，则返回rowspan:0
          return {
            rowspan: 0,
            colspan: 1,
          };
        }
      }
    }
  }
};

const createSpanrowData = (paramData, propName) => {
  if (paramData !== null && paramData.length > 0) {
    let oneArr = [];
    let currentValue = "";
    let tempFromIndex = 0;
    let tempRowspan = 1;
    for (let i = 0; i < paramData.length; i++) {
      let tempValue = "";
      // 循环propName属性数组，拼接需要合并的级联连属性
      for (let j = 0; j < propName.length; j++) {
        tempValue += paramData[i][propName[j]];
      }
      if (currentValue === tempValue) {
        // 如果当前行与上一行列属性值相同，则合并行+1
        tempRowspan++;
      } else {
        // 如果当前行与上一行列属性值不同，则更新当前行数据，添加前一组的合并参数到数组中
        currentValue = tempValue;
        if (i !== 0) {
          oneArr.push({ fromIndex: tempFromIndex, spanLength: tempRowspan });
        }
        // 并重置合并行为默认值1，更新合并开始行为当前行i
        tempRowspan = 1;
        tempFromIndex = i;
      }
    }
    // 添加最后一组合并参数到数组中
    oneArr.push({ fromIndex: tempFromIndex, spanLength: tempRowspan });
    return oneArr;
  }
};

let userTable = ref([]);
async function fetchProjectUsers(projectOid, roles) {
  try {
    const usersByRole = {};
    for (const role of roles) {
      const res = await GetProjectUsers({
        proj_oid: projectOid,
        user_role: role,
      });
      if (res.length > 0) {
        usersByRole[role] = {
          proj_oid: res[0].proj_oid,
          user_role: res[0].user_role,
          person: res.map((v) => v),
        };
      }
    }
    return Object.values(usersByRole);
  } catch (error) {
    console.error("Error fetching project users:", error);
    return [];
  }
}

async function getUserAllData() {
  try {
    const roles = ["设计人", "校核人", "审核人", "审定人"];
    let arrData = await fetchProjectUsers(proData.value.proj_oid, roles);

    userTable.value = arrData;
  } catch (error) {
    console.error("Error updating userTable:", error);
    // 处理更新失败的情况
  }
}

let getNoticeDataTabel = ref([]);
let getNotice = async (data) => {
  let res = await GetAllProjectNotices(data);
  getNoticeDataTabel.value = res;
};

let dataForm = ref({
  site_class:'',
  wind_pressure: "",
  snow_pressure: "",
  seismic_design_intensity: "",
  seismic_acceleration: "",
  seismic_design_category: "",
  modify_user: "",
  
  terrain_roughness:'',
  
});

let change_pages = (item, data) => {
  tableTitleName.value = item;

  if (tableTitleName.value == "主项管理") {
    getMarjorProData({ proj_oid: proData.value.proj_oid });
  } else if (tableTitleName.value == "交付清单") {
  } else if (tableTitleName.value == "统一规定") {
    gettableRuleDataData({
      proj_oid: proData.value.proj_oid,
      file_type: "项目统一规定",
    });
  } else if (tableTitleName.value == "通知公告") {
    getNotice({ proj_oid: proData.value.proj_oid });
  } else if (tableTitleName.value == "设备联系单") {
    gettableRuleDataData2({
      proj_oid: proData.value.proj_oid,
      file_type: "设备联系单",
    });
  } else if (tableTitleName.value == "用户管理") {
    getUserAllData();
  } else if (tableTitleName.value == "设计基础数据") {
    getGetProjBasicDesignData();
  }
};

let getGetProjBasicDesignData = async () => {
  let res = await GetProjBasicDesignData({ proj_oid: proData.value.proj_oid });

  if (res.length > 0) {
    dataForm.value = res[res.length - 1];
   
  } else {
    dataForm.value = {
      
      site_class:'',
      wind_pressure: "",
      snow_pressure: "",
      seismic_design_intensity: "",
      seismic_acceleration: "",
      seismic_design_category: "",
      modify_user: "",
      
      terrain_roughness:'',
      design_service_life_reactor_tower:'',
      design_service_life_vessel_bem:'',
      design_service_life_sphericaltank:'',
      design_service_life_storagetank:'',
    };
  }

   if(!dataForm.value.design_service_life_reactor_tower){
      dataForm.value.design_service_life_reactor_tower = 20
    }


    if(!dataForm.value.design_service_life_vessel_bem){
      dataForm.value.design_service_life_vessel_bem = 15
    }

     if(!dataForm.value.design_service_life_sphericaltank){
      dataForm.value.design_service_life_sphericaltank = 20
    }

      if(!dataForm.value.design_service_life_storagetank){
      dataForm.value.design_service_life_storagetank = 15
    }

};

let option_proState = ref([]);
let userOptionsleader = ref([]);
let optionsNewteam_leader = ref([]);
let ruleFormNew = ref({
  proj_no: "",
  proj_name: "",
  proj_status: "",
  start_time: "",
  end_time: "",
  professional_leader: null,
  team_leader: null,
  date: null,
  design_stage: "",
});

let dialogVisibleNew = ref(false);
let ruleFormRefNew = ref("");
let newPro = async () => {
  let resPerson = await GetDepartmentUsersV2({ dept: "equipment" });
  personOptions.value = resPerson.map((v) => {
    return {
      value: v.account_id,
      label: v.user_name,
    };
  });
  list_filtered.value = personOptions.value;
  personOptions_PINGYING = personOptions.value;
  ruleFormNew.value.proj_status = "运行中";
  dialogVisibleNew.value = true;
};

let AUTH_ = ref(false)
// 页面加载时
onMounted(() => {

  let code  = Number(localStorage.getItem("authCode"))
 if(code >=80){
  AUTH_.value = true
 }else{
  AUTH_.value = false
 }
  activeHeight.value =
    document.querySelector(".system-role-padding").clientHeight - 100;
  window.addEventListener("resize", () => {
    activeHeight.value =
      document.querySelector(".system-role-padding").clientHeight - 100;
  });
});
</script>

<style scoped lang="scss">
.m-header {
  display: flex;
  align-items: center;
}
.m-header .pro-name {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.m-header .el-input {
  width: 300px;
}
.m-header .el-button {
  margin-right: 10px;
}

.system-role-container {
  .system-role-padding {
    padding: 15px;
    .el-table {
      flex: 1;
    }
  }
}
.button_footer {
  display: flex;
  flex-direction: row-reverse;
  width: 100%;
}
.table_content {
  margin-top: 20px;
}

::v-deep(.el-table--large .el-table__cell) {
  padding: 6px 0;
}

.table_box {
  padding: 20px 50px;
}

.button_poastion_flex_iem {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
}

.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}

.el-tabs--right .el-tabs__content,
.el-tabs--left .el-tabs__content {
  height: 100%;
}

.backgroun_border {
  // 	::v-deep .el-tabs__header {
  //     margin-top: 39px;
  //   }
}

::v-deep(.el-tabs__item::after) {
  position: absolute;
  content: " ";
  top: 0;
  width: 2px;
  height: 100%;
  background: #eee;
  right: 0;
}


.active {
    color: rgb(24, 144, 255);
  }

  .icone {
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>
